package com.example.iot.controller;

import com.alibaba.fastjson.JSON;
import com.example.iot.util.R;
import okhttp3.*;
import org.jetbrains.annotations.NotNull;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.multipart.MultipartFile;


import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

/**
 * @author : Lin
 * @version : [v1.0]
 * @className : testcontroller
 * @description : 测试属性上报用的
 * @createTime : 2023/7/2 16:08
 * @updateUser : Lin
 * @updateTime : 2023/7/2 16:08
 * @updateRemark : 描述说明本次修改内容
 */
@RestController
public class testcontroller {

    @Value("${upload.directory}")
    private String abspath;
    @Value("${upload.reflectdirectory}")
    private String repath;
    @RequestMapping("/test")
    public String tes(@RequestBody String s){
        System.out.println("属性上报开始");
        System.out.println(s);
        System.out.println("属性上报结束");
        return s;
    }
//    @RequestMapping("/img")
//    public R img(@RequestPart("image") MultipartFile file ,@RequestPart("json") String s ){
//        try {
//            System.out.println(s);
//            Map map = JSON.parseObject(s, Map.class);
//            System.out.println(map.get("s"));
//            String filename=abspath+file.getOriginalFilename();
//            System.out.println(filename);
//            byte[] bytes = file.getBytes();
//            FileOutputStream fileOutputStream = new FileOutputStream(filename);
//            fileOutputStream.write(bytes);
//            fileOutputStream.close();
//            return R.ok(repath+file.getOriginalFilename());
//        }catch (Exception e){
//            e.printStackTrace();
//        }finally {
//
//        }
//        return R.ok(null);
//    }
    @RequestMapping("/testimg")
    public R testimg(){
        System.out.println(abspath);
        return R.ok(abspath);
    }
}
